showAlertDialog(BuildContext context) {
// set up the button
Widget okButton = FlatButton(
child: Text("OK"),
onPressed: () { },
);
// set up the AlertDialog
AlertDialog alert = AlertDialog(
title: Text("My title"),
content: Text("This is my message."),
actions: [
okButton,
],
);
// show the dialog
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
showDialog(
context: context,
child: new AlertDialog(
title: const Text("Location disabled"),
content: const Text(
"""
Location is disabled on this device. Please enable it and try again.
"""),
actions: [
new FlatButton(
child: const Text("Ok"),
onPressed: _dismissDialog,
),
],
),
);
import 'dart:async';
import 'package:flutter/material.dart';
void main() {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Trial',
home: Scaffold(
appBar: AppBar(title: Text('List scroll')), body: new MyHome()));
}
}
class MyHome extends StatelessWidget { // Wrapper Widget
@override
Widget build(BuildContext context) {
Future.delayed(Duration.zero, () => showAlert(context));
return Container(
child: Text("Hello world"),
);
}
void showAlert(BuildContext context) {
showDialog(
context: context,
builder: (context) => AlertDialog(
content: Text("hi"),
));
}
}
//custom_alert_dialog.dart
import 'package:flutter/material.dart';
class CustomAlertDialog extends StatefulWidget {
const CustomAlertDialog({
Key? key,
required this.title,
required this.description,
}) : super(key: key);
final String title, description;
@override
_CustomAlertDialogState createState() => _CustomAlertDialogState();
}
class _CustomAlertDialogState extends State<CustomAlertDialog> {
@override
Widget build(BuildContext context) {
return Dialog(
elevation: 0,
backgroundColor: Color(0xffffffff),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(height: 15),
Text(
"${widget.title}",
style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 15),
Text("${widget.description}"),
SizedBox(height: 20),
Divider(
height: 1,
),
Container(
width: MediaQuery.of(context).size.width,
height: 50,
child: InkWell(
highlightColor: Colors.grey[200],
onTap: () {
//do somethig
},
child: Center(
child: Text(
"Continue",
style: TextStyle(
fontSize: 18.0,
color: Theme.of(context).primaryColor,
fontWeight: FontWeight.bold,
),
),
),
),
),
Divider(
height: 1,
),
Container(
width: MediaQuery.of(context).size.width,
height: 50,
child: InkWell(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(15.0),
bottomRight: Radius.circular(15.0),
),
highlightColor: Colors.grey[200],
onTap: () {
Navigator.of(context).pop();
},
child: Center(
child: Text(
"Cancel",
style: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.normal,
),
),
),
),
),
],
),
);
}
}